<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>INSPINIA | Basic Form</title>
	<link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
	<link href="#springUrl('/static/css/style.css')" rel="stylesheet">
    <style>
        .news-content textarea{
            width: 500px;
            height: 120px;
        }
    </style>
</head>
<body class="white-bg">
<div class="ibox-content" style="width: 430px;">
   <form id="myForm" class="form-horizontal" autocomplete="off" data-validator-option="{theme:'default'}">
   	   <input type="hidden" name="id" value="$!{news.id}">
       <div class="form-group"><label class="col-sm-2 control-label">标题</label>
           <div class="col-sm-10">
           		<input type="text" class="form-control" value="$!{news.title}" name="title" data-rule="用户名:required;title">
           </div>
       </div>
       <div class="hr-line-dashed"></div>
       <div class="form-group"><label class="col-sm-2 control-label">摘要</label>
           <div class="col-sm-10">
           		<input type="text" class="form-control" value="$!{news.summary}" name="summary" data-rule="摘要:summary">
           </div>
       </div>
       <div class="hr-line-dashed"></div>
       <div class="form-group"><label class="col-sm-2 control-label">缩略图</label>
           <div class="col-sm-10">
               <input type="text" class="form-control" value="$!{news.thumbnail}" name="thumbnail" data-rule="缩略图:thumbnail">
           </div>
       </div>
       <div class="form-group"><label class="col-sm-2 control-label">内容</label>
           <div class="col-sm-10 news-content">
               <script id="editor" type="text/plain" name="content" style="width:500px;height:500px;"></script>
               <!--<textarea name="content">
                 $!{news.thumbnail}
               </textarea>-->
           </div>
       </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="text-center">
                <button class="btn btn-primary" type="submit">#if($!{news})修 改#else提 交#end</button>
            </div>
        </div>
    </form>
</div>
<script src="#springUrl('/static/js/jquery-2.1.1.js')"></script>
<script src="#springUrl('/static/plugins/nice-validator-0.8.1/jquery.validator.js?local=zh-CN')"></script>
<script type="text/javascript" charset="utf-8" src="#springUrl('/static/js/plugins/ueditor/ueditor.config.js')"></script>
<script type="text/javascript" charset="utf-8" src="#springUrl('/static/js/plugins/ueditor/ueditor.all.min.js')"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="#springUrl('/static/js/plugins/ueditor/lang/zh-cn/zh-cn.js')"></script>
<script type="text/javascript">
    var ue = UE.getEditor('editor');
    //对编辑器的操作最好在编辑器ready之后再做
    ue.ready(function() {
        var newsId = $("input[name=id]").val();
        if(newsId!="") {
            $.post("/sys/news/$!{news.id}", function (data) {
                if (data) {
                    //设置编辑器的内容
                    ue.setContent(data.content);
                }
            });
        }
        //var html = $("#hideContent").val();
        //设置编辑器的内容
        //ue.setContent(html);
    });
$("#myForm").validator({
    valid: function(form){
        var me = this;
        // 提交表单之前，hold住表单，防止重复提交
        me.holdSubmit();
        $.ajax({
        	url: "#springUrl('/sys/news/editNews')",
            data: $(form).serialize(),
            type: "POST",
            success: function(data){
            	var d = JSON.parse(data);
                if(d.success && d.data){
                	window.parent.location.reload();
                	//当你在iframe页面关闭自身时
                	//var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                	//parent.layer.close(index); //再执行关闭   
                } else {
                	//失败，提交表单成功后，释放hold，如果不释放hold，就变成了只能提交一次的表单
                    me.holdSubmit(false);
                }
            }
        });
    }
});
</script>
</body>
</html>
